package com.mistyrain.service.impl;

import com.mistyrain.entity.Order;
import com.mistyrain.entity.OrderVO;
import com.mistyrain.mapper.OrderMapper;
import com.mistyrain.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Override
    public void save(Order order) {
        orderMapper.save(order);
    }

    @Override
    public OrderVO findAllByUid(long uid, int index, int limit) {
        OrderVO orderVO = new OrderVO();
        orderVO.setCode(0);
        orderVO.setMsg("");
        orderVO.setCount(orderMapper.countByUid(uid));
        orderVO.setData(orderMapper.findAllByUid(uid,(index-1)*limit,limit));
        return orderVO;
    }

    @Override
    public int countByUid(long uid) {
        return orderMapper.countByUid(uid);
    }

    @Override
    public void deleteByMid(long mid) {
        orderMapper.deleteByMid(mid);
    }

    @Override
    public void deleteByUid(long uid) {
        orderMapper.deleteByUid(uid);
    }

    @Override
    public OrderVO findAllByState(int state, int page, int limit) {
        OrderVO orderVO = new OrderVO();
        orderVO.setCode(0);
        orderVO.setMsg("");
        orderVO.setCount(orderMapper.countByState(0));
        orderVO.setData(orderMapper.findAllByState(0,(page-1)*limit,limit));
        return orderVO;
    }

    @Override
    public int countByState(int state) {
        return orderMapper.countByState(state);
    }

    @Override
    public void updateState(long id, long aid, int state) {
        orderMapper.updateState(id, aid, state);
    }
}
